package net.pws.common.persistence.hibernate3;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.Map;

import org.apache.commons.collections.map.CaseInsensitiveMap;
import org.springframework.jdbc.core.RowMapper;

/**
 * 返回不区分大小Key的CaseInsensitiveMap的RowMapper实现
 * @author LiangBin
 *
 */
public class CaseInsensitiveMapRowMapper implements RowMapper<Map> {

    public Map mapRow(ResultSet rs, int arg1) throws SQLException {
        Map result = new CaseInsensitiveMap();
        ResultSetMetaData resultSetMetadata = rs.getMetaData();
        int columnCount = resultSetMetadata.getColumnCount();
        for (int i = 0; i < columnCount; i++) {
            String columnName = resultSetMetadata.getColumnName(i + 1);
            result.put(columnName, rs.getObject(columnName));
        }
        return result;
    }
    
}
